package com.loong.seller.handler;

import com.loong.common.domain.BaseQuery;
import com.loong.common.domain.Pager;
import com.loong.common.utils.TransformUtils;
import com.loong.seller.business.CompanyBusiness;
import com.loong.seller.common.backend.param.CompanyParam;
import com.loong.seller.common.backend.param.CompanyQueryParam;
import com.loong.seller.common.backend.result.CompanyResult;
import com.loong.seller.model.Company;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 企业服务
 * @Author: hzp
 * @Date: 2020-10-26 11:14
 */
@Component
public class CompanyHandler {
    @Resource
    private CompanyBusiness companyBusiness;
    /**
     * 保存企业信息
     * @param param 企业信息
     */
    public void save(CompanyParam param){
        companyBusiness.save(TransformUtils.transform(param, Company.class));
    }

    /**
     * 更新企业信息
     * @param param 企业信息
     */
    public void update(CompanyParam param){
        companyBusiness.updateByPrimaryKeySelective(TransformUtils.transform(param, Company.class));
    }

    /**
     *根据id删除企业信息
     * @param id 企业id
     */
    public void deleteById(Long id){
        companyBusiness.deleteById(id);
    }


    /**
     * 分页查询
     * @param baseQuery 分页对象
     * @param param 分页参数
     * @return
     */
    public Pager<CompanyResult> pageQuery(BaseQuery baseQuery, CompanyQueryParam param){
        Pager<Company> manageApisPager = companyBusiness.pageQuery(baseQuery, () -> companyBusiness.query(param));
        return TransformUtils.transformPage(manageApisPager, CompanyResult.class);
    }

}
